var express = require('express');
var router = express.Router();
const filmService = require('../service/filmService');
router.get('/all',async function(req, res, next) {
    res.send(await filmService.findAll());
});
router.get('/:id',async function(req, res, next) {
    res.send(await filmService.findById(req.params.id));
});

router.get('/',async function(req, res, next) {
    let {type,value,current,size} = req.query;
    let searchObj = {};
    if(type){
        searchObj[type] = {$regex:value};
    }
    let data = await filmService.find(searchObj,{current:current||1,size:size||5});
    res.send(data);
});

module.exports = router;
